import smtplib
from datetime import datetime
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from socket import AF_INET, SOCK_STREAM, socket

import requests
from twisted.words.protocols.jabber.jstrports import client


def main():
    resp = requests.get('http://api.tianapi.com/meinv/?key=APIKey&num=10')
    # 将服务器返回的JSON格式的数据解析为字典
    resp = resp.json()
    print(resp)


def main1():
    server = socket(family=AF_INET, type=SOCK_STREAM)
    server.bind(('127.0.0.1', 8082))
    # 参数512可以理解为连接队列的大小
    server.listen(512)
    print('服务器启动开始监听...')
    while True:
        client, addr = server.accept()
        print(str(addr) + "连接服务器")
        client.send(str(datetime.now()).encode('utf-8'))
        client.close()


def sendEmail(sendEmail, receiverEmail):
    message = MIMEText("ttttttttttttsss", 'plain', 'utf-8')
    message['From'] = Header("王大锤", "utf-8")
    message["To"] = Header("骆驼", "utf-8")
    message["Subject"] = Header("shshshshsh", "utf-8")
    smtper = smtplib.SMTP('smtp.126.com')
    smtper.login("1111", "2222")
    smtper.sendmail(sendEmail, receiverEmail, message.as_string())
    print("邮件发送完成")


if __name__ == '__main__':
    main1()
    receiverEmail = ["111@qq.com","222.qq.com"]
    sendEmail("330059579@qq.com", receiverEmail)